<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
class Common extends Controller
{
    public function http($url){
		
		header("Content-type: text/html; charset=utf-8"); 
		
        $ch = curl_init($url);
		
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
		
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		
        curl_setopt($ch, CURLOPT_HEADER, false);
		
        $output = curl_exec($ch);//输出内容
		
        curl_close($ch);
		
        return array($output);
    } 
	public function https_post($url, $data = null){
		
		$curl = curl_init();
		 
		curl_setopt($curl, CURLOPT_URL, $url);
		 
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		 
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
		 
		if (!empty($data)){
			 
			curl_setopt($curl, CURLOPT_POST, 1);
			 
			curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
			 
		}
		 
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		 
		$output = curl_exec($curl);
		 
		curl_close($curl);
		 
		return $output;
		 
	}
	public function province(){
		$url=config('tdwApi')."/area/getAllProvince.jhtml";
		$res=$this->http($url);
		$res=json_decode($res[0],true);
		echo json_encode($res);	
	}
	public function city(){
		$id=input('post.id');
		$url=config('tdwApi')."/area/getCitysByProvinceId.jhtml?id=$id";
		$res=$this->http($url);
		$res=json_decode($res[0],true);
		echo json_encode($res);	
	}
	public function county(){
		$id=input('post.id');
		$url=config('tdwApi')."/area/getCountysByCityId.jhtml?id=$id";
		$res=$this->http($url);
		$res=json_decode($res[0],true);
		echo json_encode($res);	
	}
		/**
		 *  创建静态页面
		 * @access protected
		 * @htmlfile 生成的静态文件名称
		 * @htmlpath 生成的静态文件路径
		 * @param string $templateFile 指定要调用的模板文件
		 * 默认为空 由系统自动定位模板文件
		 * @return string
		 */
		public function buildHtml($htmlfile='',$htmlpath='',$templateFile='') {
			
		    $content    =   $this->fetch($templateFile);
		    $htmlpath   =   !empty($htmlpath)?$htmlpath:'./';
		    $htmlfile   =   $htmlpath.$htmlfile.'.html';
		    //Storage::put($htmlfile,$content,'html');
		    
		    $ret = $this->put($htmlfile, $content);
		    //$ret = file_put_contents($htmlfile, $content);
		    
		    return $content;
		}

		public function put($filename,$content,$type=''){
		    $dir         =  dirname($filename);
		    if(!is_dir($dir)){
		        mkdir($dir,0777,true);
		    }
		    if(false === file_put_contents($filename,$content)){
		        E(L('_STORAGE_WRITE_ERROR_').':'.$filename);
		    }else{
		        $this->contents[$filename]=$content;
		        return true;
		    }
		}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
